<template>
    <div>
        <h1>科室列表</h1>
        <a target="_blank" href="https://localhost:7215/api/Ks/Dc">导出科室信息文件</a>
        <br>
        <input type="text" placeholder="科室名称查询" v-model="cs.name">
        创建日期:
        <input type="date" v-model="cs.stime">-<input type="date" v-model="cs.etime">
        <input type="button" value="查询" class="btn btn-success" @click="show">
        <input type="button" value="重置" class="btn btn-success" @click="cz">
        <table class="table">
            <thead>
                <tr>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{ d.kname }}</td>
                    <td>{{ d.ksnum }}</td>
                    <td>{{ d.kRemark }}</td>
                    <td>{{ moment(d.kCreateTime).format("yyyy-MM-DD hh:mm:ss") }}</td>
                    <td>
                        <input type="button" value="删除" class="btn btn-success" @click="del(d.kid)">
                        <input type="button" value="修改" class="btn btn-success" @click="upd(d.kid)">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/ksadd">科室添加</a>
        <br>
        <a href="/ysadd">医生添加</a>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter } from 'vue-router';
const router=useRouter()
//修改
const upd=(mid:any)=>{
    router.push({path:"/updks",query:{id:mid}})
}
//重置
const cz=()=>{
    cs.value.name="",
    cs.value.stime=null,
    cs.value.etime=null
}
//参数
const cs=ref({
    name:'',
    stime:null,
    etime:null
})
//删除
const del=(mid:any)=>{
    if(confirm('您确定要删除吗')){
        axios.get("/api/Ks/DelKs",{params:{id:mid}}).then(res=>{
            if(res.data>0){
                alert('删除成功');
                show()
            }
            else{
                alert('删除失败');
                return;
            }
        })
    }
}

const data=ref([
    {
    "kid": 1,
    "kname": "内科",
    "ksnum": 14,
    "kRemark": "专治内科疾病",
    "kCreateTime": "2025-05-19T00:00:00",
    "isdelete": false
  }
])
//文档就续
onMounted(()=>{
    show()
})
//显示
const show=()=>{
    axios.get("/api/Ks/GetKs",{params:cs.value}).then(res=>{
        data.value=res.data
    })
}
</script>

<style scoped>

</style>